package com.approval.approval;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.QjxqBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class QjSplcAdapter extends RecyclerView.Adapter<QjSplcAdapter.Holder> {

    List<QjxqBean.ListBean> listBeanList;

    public void setListBeanList(List<QjxqBean.ListBean> listBeanList) {
        this.listBeanList = listBeanList;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_jg,parent,false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        holder.tv1.setText(listBeanList.get(position).getHandle_Name());
        if (listBeanList.get(position).getState() == 0 ||
                listBeanList.get(position).getState() == 4){
        holder.tv2.setText("审核不通过");
        holder.tv2.setTextColor(Color.parseColor("#DE463A"));
        }else if (listBeanList.get(position).getState() == 1 ||
                listBeanList.get(position).getState() == 3
                || listBeanList.get(position).getState() == 7){
            holder.tv2.setText("审核通过");
            holder.tv2.setTextColor(Color.parseColor("#FF1465FD"));
        }else {
            holder.tv2.setText("");
        }
        holder.tv3.setText(listBeanList.get(position).getHandle_date());
        if (listBeanList.get(position).getHandle_YJ() == null || TextUtils.isEmpty(listBeanList.get(position).getHandle_YJ() )){
            holder.tv4.setText("");
        }else {
            holder.tv4.setText("办理意见： " + listBeanList.get(position).getHandle_YJ());
        }
        holder.index_tv.setText((position + 1) + "");
    }

    @Override
    public int getItemCount() {
        if (listBeanList == null){
            return 0;
        }else {
            return listBeanList.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder{
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv2)
        TextView tv2;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.v1)
        View v1;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.index_tv)
        TextView index_tv;

        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
